package com.migu.rbac.service;

import com.migu.rbac.repository.SysMenuBackApiRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description TODO :
 * @Author: zj
 * @Date: 14:33 2019/4/4
 * @Version 1.0
 **/
@Service
@Transactional
public class SysMenuBackApiService {
    @Autowired
    SysMenuBackApiRepository menuBackApiRepository;

    //删除菜单对应所有接口
    public Boolean deleteMenuApiBymenuId(int menuid) {
        if (menuBackApiRepository.deleteMenuApiBymenuId(menuid) > 0) {
            return true;
        } else {
            return false;
        }
    }

    //保存菜单对应接口
    public Boolean saveMenuApi( int menuid, Integer[] apis) {
        //先删除已有path
        deleteMenuApiBymenuId(menuid);
        if (apis.length < 0) {
            return false;
        }
        if (menuBackApiRepository.saveMenuApi(menuid, apis) > 0) {
            return true;
        } else {
            return false;
        }
    }

    //查询菜单所有apiid
    public int[] selectApiByMenuId( int menuid) {
        return menuBackApiRepository.selectApiByMenuId(menuid);
    }
}
